#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>
#include <QAction>
#include <QFileDialog>
#include <QFile>
#include <QFileInfo>
#include <QVector>
#include <QThread>
#include <QMetaType>

#include <qcustomplot.h>

#include "ui_MainWin.h"
#include "addpointdlg.h"
#include "settingsdlg.h"
#include "point.h"
#include "utils.h"
#include "runtaskthread.h"
#include "waitdlg.h"

class ReadFileThread : public QThread{

    Q_OBJECT
signals:
    void readFinished(QVector<Point> pointArr);
private:
    QString file;
    QVector<Point> pointArr;
public:
    ReadFileThread(const QString &fn){
        file=fn;
    }
    // QThread interface
protected:
    virtual void run() override;
};

class MainWindow : public QMainWindow
{
    Q_OBJECT

public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();
private:
    Ui::MainWindow *ui;
    QVector<Point> pointArr;
    ReadFileThread *readTh;
    RunTaskThread *taskTh;
    QCPCurve *graphC;
    QCustomPlot *plot;
    QVector<double> sets;
    waitDlg *dlg;
private:
    void readSets();
    void drawPoints(const QVector<Point>&);
    void drawResult(const QVector<int>&);
private slots:
    void openAddPointWin();
    void openSettings();
    void openFileDlg();
    void onPointReadFinished(QVector<Point> arr);
    void rePaint();
    void saveLog();
    void savePoints();
    void startCalc();
    void onCalcFinished(QVector<int>,QString);
    void updateSets();
};

#endif // MAINWINDOW_H
